package com.tzy.evaluation.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.tzy.common.entity.Comments;
import org.apache.ibatis.annotations.MapKey;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 评论表 Mapper 接口
 * </p>
 *
 * @author 谭同学
 * @since 2022-03-18
 */
public interface CommentMapper extends BaseMapper<Comments> {
    /**
     * 查询所有一级评论
     * @param evaluationId
     * @param pageNum
     * @param size
     * @return
     */
    @MapKey("")
    List<Map<String, Object>> findAllFirstLevelReviews(int evaluationId,Integer pageNum,Integer size);
    /**
     *
     * @param replyId
     * @param evaluationId
     * @param pageNum
     * @param size
     * @return
     */
    @MapKey("")
    List<Map<String, Object>> userComment( int evaluationId,Integer pageNum, Integer size);
    /**
     *
     * @param evaluationId
     * @param pageNum
     * @param size
     * @return
     */
    @MapKey("")
    List<Map<String, Object>> replyUser(int replyId,int evaluationId,Integer pageNum,Integer size);
    /**
     *
     * @param id
     * @param evaluationId
     * @return
     */
    @Select("select count(*) from user u\n" +
            "JOIN comments c \n" +
            "where c.user_id=u.id \n" +
            "and c.parent_id=#{id} and c.evaluation_Id=#{evaluationId} LIMIT 1")
    int commentCount(Integer id, Integer evaluationId);
    /**
     *
     * @param evaluationId
     * @return
     */
    @Select("select count(*) from comments  where evaluation_Id=#{evaluationId}s LIMIT 1")
    int commentCounts(Integer evaluationId);

}
